package com.epam.OOP.transport;

import com.epam.OOP.utils.BundlesReader;
import com.epam.OOP.utils.PropertiesReader;
import com.epam.OOP.utils.Validator;

import java.io.UnsupportedEncodingException;

/**
 * Created with IntelliJ IDEA.
 * User: Yelena_M
 * Date: 04.08.13
 * Time: 17:27
 * To change this template use File | Settings | File Templates.
 */
public class Van extends Lorry{

    private static PropertiesReader propertiesReader = new PropertiesReader();

    private Integer lengthPlace; //Length unuseful place in lorry body
    private Integer widthPlace; //Width unuseful place in lorry body
    private Integer heightPlace; //Height unuseful place in lorry body

    public Van(){
        super();
    }

    public Van(Integer lengthBody, Integer widthBody, Integer heightBody,
               Integer lengthPlace, Integer widthPlace, Integer heightPlace) {
        super();
        this.lengthPlace = lengthPlace;
        this.widthPlace = widthPlace;
        this.heightPlace = heightPlace;
    }

    public int getLengthPlace() {
        return lengthPlace;
    }

    public void setLengthPlace(Integer lengthPlace) {
        this.lengthPlace = lengthPlace;
    }

    public int getWidthPlace() {
        return widthPlace;
    }

    public void setWidthPlace(Integer widthPlace) {
        this.widthPlace = widthPlace;
    }

    public int getHeightPlace() {
        return heightPlace;
    }

    public void setHeightPlace(Integer heightPlace) {
        this.heightPlace = heightPlace;
    }

    @Override
    public String toString() {
        return "Van{" +
                "lengthPlace=" + lengthPlace +
                ", widthPlace=" + widthPlace +
                ", heightPlace=" + heightPlace +
                '}';
    }

    /**
     * Count useful volume = volume of body car - useless volume of body car
     * which can't use for goods (tools for fixing)
     * */
    public static int realVanVolumeCount(int lengthPlace, int widthPlace, int heightPlace) throws UnsupportedEncodingException {
        int volume = 0;

        int transportVolume = Transport.volumeCount(Integer.parseInt(propertiesReader.getProperties("lengthBody")),
                Integer.parseInt(propertiesReader.getProperties("widthBody")),
                Integer.parseInt(propertiesReader.getProperties("heightBody")));

        if ((!Validator.checkDataForDigital(String.valueOf(transportVolume))) &&
            (!Validator.checkDataForDigital(String.valueOf(lengthPlace))) &&
            (!Validator.checkDataForDigital(String.valueOf(widthPlace))) &&
            (!Validator.checkDataForDigital(String.valueOf(heightPlace)))) {
                BundlesReader.read("MessageWrongData");
                System.exit(0);
        } else  {
            volume =  transportVolume
                    - lengthPlace * widthPlace * heightPlace;
        }
        return volume;
    }
}
